import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  
  {
    path: '/k8s',
    component: Layout,
    name: 'k8s',
    meta: { title: 'Kubernetes', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'deployment',
        name: 'Deployments',
        component: () => import('@/views/k8s/deployments'),
        meta: { title: 'Deployments', icon: 'table' }
      },
      {
        path: 'service',
        name: 'Services',
        component: () => import('@/views/k8s/services'),
        meta: { title: 'Services', icon: 'table' }
      },
      {
        path: 'istiogateway',
        name: 'Istiogateways',
        component: () => import('@/views/tree/index'),
        meta: { title: 'IstioGateways', icon: 'table'},
      },
      {
        path: 'istiovirtualservice',
        name: 'IstioVS',
        component: () => import('@/views/tree/index'),
        meta: { title: 'IstioVS', icon: 'table'},
      },
      {
        path: 'ingress',
        name: 'Ingress',
        component: () => import('@/views/k8s/ingress-nginx'),
        meta: { title: 'Ingress', icon: 'table'},
      },
      {
        path: 'logs',
        name: 'Logs',
        component: () => import('@/views/k8s/podLogs'),
        meta: { title: 'Logs', icon: 'table' }
      }
    ]
  },

  {
    path: '/project',
    name: 'project',
    component: Layout,
    meta: { title: 'Project', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'createproject',
        name: 'CreateProject',
        component: () => import('@/views/project/createProject'),
        meta: { title: 'Create Project', icon: 'form' }
      },
      {
        path: 'projectlist',
        name: 'ProjectList',
        component: () => import('@/views/project/listProject'),
        meta: { title: 'List Project', icon: 'form' },
      }
    ]
  },

  {
    path: '/devops',
    name: 'DevOps',
    component: Layout,
    meta: { title: 'DevOps', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'tekton',
        name: 'Tekton',
        component: () => import('@/views/form/index'),
        meta: { title: 'Tekton', icon: 'form'},
      },
      {
        path: 'argoworkflow',
        name: 'ArgoWorkflow',
        component: () => import('@/views/form/index'),
        meta: { title: 'ArgoWorkflow', icon: 'form'},
      },
      {
        path: 'jenkins',
        name: 'Jenkins',
        component: () => import('@/views/form/index'),
        meta: { title: 'Jenkins', icon: 'form'},
      },
      {
        path: 'wiki',
        name: 'Wiki',
        component: () => import('@/views/form/index'),
        meta: { title: '文档', icon: 'form' },
      }
    ]
  },

  {
    path: '/teamates',
    name: 'Teamates',
    component: Layout,
    meta: { title: '团队成员', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'managers',
        component: Layout,
        meta: { title: '项目管理', icon: 'el-icon-s-help' },
      },
      {
        path: 'developers',
        component: Layout,
        meta: { title: '开发者', icon: 'el-icon-s-help' },
      },
      {
        path: 'operations',
        component: Layout,
        meta: { title: '运维', icon: 'el-icon-s-help' },
      },
      {
        path: 'testers',
        component: Layout,
        meta: { title: '测试', icon: 'el-icon-s-help' },
      }
    ]
  },

  {
    path: '/chatOps',
    name: 'ChatOps',
    component: Layout,
    meta: { title: 'ChatOps', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'chatroom',
        component: Layout,
        meta: { title: '聊天室', icon: 'el-icon-s-help' }
      },
      { 
        path: 'test',
        component: Layout,
        meta: { title: 'test', icon: 'el-icon-s-help' }
      }
    ]
  },

  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
